package com.example.algorithmdemo.stack;

import java.util.Stack;

public final class MinStack {
    private Stack<Integer> pushStack = new Stack<Integer>();
    private Stack<Integer> minValueStack = new Stack<Integer>();
    public void push(int value){
        pushStack.push(value);
        if (minValueStack.isEmpty() || minValueStack.peek() > value){
            minValueStack.push(value);
        }
    }
    public int pop(){
        if (!pushStack.isEmpty()){
            if (pushStack.peek() == minValueStack.peek()){
                minValueStack.pop();

            }
            return pushStack.pop();
        }else {
            System.out.print("stack is empty");
            return -1;
        }
    }
    public int top(){
        return pushStack.peek();
    }
    public int minValue(){
        return minValueStack.peek();
    }
}
